package com.mti.monitor.service;

import com.mti.monitor.config.properties.LicenseProperties;
import com.mti.monitor.util.LicenseUtils;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 * 发送短信工具类
 */
@Service
@Log4j2
public class AuthMonitorService {


	private static final String PK_FILE = "/public.pem";
	private static final String SN_FILE = "/sn.pem";

	@Autowired
	private LicenseProperties licenseProperties;

	public boolean checkAuth(){
		String sn = getSn();
		String pk = getPublicKey();
		if (sn == null || pk == null) {
			return false;
		}
		String machineCode = LicenseUtils.getMachineCode(licenseProperties.getAuthcode());
		return LicenseUtils.checkLicence(pk, sn, machineCode);
	}

	private String getPublicKey() {
		String path = licenseProperties.getCertpath() + "/" + PK_FILE;
//		if (FileUtils.checkFileExist(path)) {
//			return FileUtils.readFile(path);
//		}
		return null;
	}

	private String getSn() {
		String path = licenseProperties.getCertpath() + "/"  + SN_FILE;
//		if (FileUtils.checkFileExist(path)) {
//			return FileUtils.readFile(path);
//		}
		return null;
	}
}
